package com.example.rbm;

import com.example.consts.RbmConsts;
import com.example.service.SavePosClickService;
import com.rabbitmq.client.Channel;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * 本文来演示
 *
 * @author 赵建云
 * @create 2023/10/18
 */
@Slf4j
@Component
public class RbmDeadService {
    @Autowired
    private SavePosClickService savePosClickService;
    @RabbitHandler
    @RabbitListener(queues = RbmConsts.ROOTING_DEAD_QUEUE)
    public void handleClick(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG)long tag){
        log.info("接收到的死信消息为:[{}]",msg);
        try {
            channel.basicAck(tag,false);
        } catch (IOException e) {
            log.error("死信队列消息签收失败",e);
        }
    }
}
